package org.hotelsystem.hoteladminsystem.Service.IMP;

import org.hotelsystem.hoteladminsystem.Mapper.LiuyanMapper;
import org.hotelsystem.hoteladminsystem.Mapper.LiuyanWithUserMapper;
import org.hotelsystem.hoteladminsystem.Pojo.Liuyan;
import org.hotelsystem.hoteladminsystem.Pojo.LiuyanWithUser;
import org.hotelsystem.hoteladminsystem.Service.LiuyanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LiuyanServiceIMP implements LiuyanService {

    @Autowired
    private LiuyanMapper liuyanMapper;

    @Autowired
    private LiuyanWithUserMapper liuyanWithUserMapper;

    /**
     * @param hotelId
     * @return
     */
    @Override
    public Map<String, Object> getLiuyansByHotelId(int hotelId) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<Liuyan> liuyans = liuyanMapper.getLiuyanByHotelId(hotelId);
            result.put("code", 200);
            result.put("result", true);
            result.put("msg", "success");
            result.put("count", liuyans.size());
            result.put("data", liuyans);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("result", false);
            result.put("msg", "failed");
            result.put("count", 0);
            result.put("data", null);
        }
        return result;
    }

    /**
     * @param hotelId
     * @return
     */
    @Override
    public Map<String, Object> getLiuyanAndUserByhotelId(int hotelId) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<LiuyanWithUser> liuyans = liuyanWithUserMapper.getLiuyanWithUserByHotelId(hotelId);
            result.put("code", 200);
            result.put("result", true);
            result.put("msg", "success");
            result.put("count", liuyans.size());
            result.put("data", liuyans);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("result", false);
            result.put("msg", "failed");
            result.put("count", 0);
            result.put("data", null);
        }
        return result;
    }
}
